#!/bin/sh -e

. CI/travis/lib.sh
. CI/travis/before_install_lib.sh

brew_install_if_not_exists cmake fftw libmatio \
	libxml2 pkg-config libusb gtk+ gtkdatabox \
	jansson glib curl openssl@1.1 \
	gettext libserialport python

if [ -n "$PACKAGE_TO_INSTALL" ] ; then
	for file in $PACKAGE_TO_INSTALL ; do
		sudo installer -pkg "${file}" -target /
	done
elif [ "$INSTALL_FROM_SW_DOWNLOADS" = "1" ] ; then
	for pkg in libiio libad9361-iio libad9166-iio ; do
		wget http://swdownloads.analog.com/cse/travis_builds/master_latest_${pkg}${LDIST}.pkg
		sudo installer -pkg master_latest_${pkg}${LDIST}.pkg -target /
	done
else
	cmake_build_git "libiio" "https://github.com/analogdevicesinc/libiio" "" "-DINSTALL_UDEV_RULE:BOOL=OFF"

	cmake_build_git "libad9361-iio" "https://github.com/analogdevicesinc/libad9361-iio" "" "-DLIBIIO_INCLUDEDIR:PATH=$STAGINGDIR/include -DLIBIIO_LIBRARIES:FILEPATH=$STAGINGDIR/lib/libiio.dylib"
	cmake_build_git "libad9166-iio" "https://github.com/analogdevicesinc/libad9166-iio" "" "-DLIBIIO_INCLUDEDIR:PATH=$STAGINGDIR/include -DLIBIIO_LIBRARIES:FILEPATH=$STAGINGDIR/lib/libiio.dylib"
fi
